// import dayjs from 'dayjs';

//弹出窗
export function showToast(title, icon) {
	uni.showToast({
		title: title,
		icon: icon ? icon : 'none',
	});
}

//时间戳转时间
export function formatDate(value) {
	let date = new Date(value);
	let y = date.getFullYear();
	let MM = date.getMonth() + 1;
	MM = MM < 10 ? ('0' + MM) : MM;
	let d = date.getDate();
	d = d < 10 ? ('0' + d) : d;
	let h = date.getHours();
	h = h < 10 ? ('0' + h) : h;
	let m = date.getMinutes();
	m = m < 10 ? ('0' + m) : m;
	let s = date.getSeconds();
	s = s < 10 ? ('0' + s) : s;
	return y + '-' +MM + '-' +d + ' ' +h + ':'+m + ':'+s;
}
/**
 * 函数防抖 (只执行最后一次点击)
 */
 export const Debounce = (fn, t) => {
	let delay = t || 300;
	let timer;
	return function () {
	  let args = arguments;
	  if (timer) {
		clearTimeout(timer);
	  }
	  timer = setTimeout(() => {
		timer = null;
		fn.apply(this, args);
	  }, delay);
	}
  };


  /**
 * 获取当前用户位置
 */
  export const getWxLocation = () => {
	console.log('定位中...')
	return new Promise((resolve, reject) => {
	  let _locationChangeFn = (res) => {
		console.log('获取到定位', res)
		resolve(res)
		wx.offLocationChange(_locationChangeFn)
	  }
	  wx.startLocationUpdate({
		isHighAccuracy: true, // 开启地图精准定位
		type: 'gcj02',
		success: (res) => {
		  console.log(res);
		  wx.onLocationChange(_locationChangeFn)
  
		},
		fail: (err) => {
		  console.log('获取当前位置失败', err)
		  reject(err)
		}
	  })
	})
  }

